package com.tjsinfo.tjsoa.fileDocument.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.fileDocument.bo.FileDocumentUserBo;
import com.tjsinfo.tjsoa.fileDocument.vo.FileDocumentGroup;
import com.tjsinfo.tjsoa.fileDocument.vo.FileDocumentUser;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;

public class UpdateUserRolesAction extends Action{
	private FileDocumentUserBo fileDocumentUserBo;
	


	public FileDocumentUserBo getFileDocumentUserBo() {
		return fileDocumentUserBo;
	}



	public void setFileDocumentUserBo(FileDocumentUserBo fileDocumentUserBo) {
		this.fileDocumentUserBo = fileDocumentUserBo;
	}



	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		String groupid  = request.getParameter("groupid");
		String userid = request.getParameter("userid");
		String[] useridarray = userid.split(","); 
		fileDocumentUserBo.deleteByGroup(groupid);
		for (String id : useridarray) {
			if (id != null && !"".equals(id)) {
				FileDocumentUser fileDocumentUser = new FileDocumentUser();
				FileDocumentGroup fileDocumentGroup = new FileDocumentGroup();
				fileDocumentGroup.setId(groupid);
			    TSystemUser systemUser = new TSystemUser();
				systemUser.setUserId(Integer.parseInt(id));
				fileDocumentUser.setFileDocumentGroup(fileDocumentGroup);
				fileDocumentUser.setTjsUser(systemUser);
				fileDocumentUserBo.addGroupUser(fileDocumentUser);
				
			}
		}
		JSONObject object = new JSONObject();
    	object.put("success", true);
		response.getWriter().print(object);
		return  null;
	}
	
	
}

